package com.itnoob.service;

import com.itnoob.event.OrderStatusChangeEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Service;

import static com.itnoob.status.OrderStatusEnum.DELIVERED;
import static com.itnoob.status.OrderStatusEnum.PAID;
import static com.itnoob.status.OrderStatusEnum.CANCELED;
/**
 * @author zhoujun
 * @date 2025/3/20 20:42
 */
@Service
public class PaymentService implements ApplicationListener<OrderStatusChangeEvent> {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public void onApplicationEvent(OrderStatusChangeEvent event) {
        //根据不同的订单状态,执行不同的库存操作
        switch (event.getOrderStatus()){
            case PAID:
                //创建支付单
                createPayment(event.getOrderId());
                break;
            case DELIVERED:
                confirmPayment(event.getOrderId());
                break;

            case CANCELED:
                cancelPayment(event.getOrderId());
                break;

            default:
                break;

        }
    }

    private void createPayment(String orderId) {
        logger.info("[createPayment]创建支付请求({})的支付请求",orderId);
    }

    private void cancelPayment(String orderId) {
        logger.info("[cancelPayment]取消支付({})的支付请求",orderId);
    }

    private void confirmPayment(String orderId) {
        logger.info("[confirmPayment]确认支付({})的支付订单",orderId);
    }
}
